#include<iostream>  
#include<vector>  
  
using namespace std;  
  
struct SparseMatrix {  
    int row;  
    int col;  
    vector<vector<int>> values;  
};  
  
SparseMatrix add(SparseMatrix a, SparseMatrix b) {  
    SparseMatrix result;  
    result.row = a.row;  
    result.col = a.col;  
    result.values.resize(a.values.size());  
  
    for (int i = 0; i < a.values.size(); i++) {  
        for (int j = 0; j < a.values[i].size(); j++) {  
            if (a.values[i][j] != 0 && b.values[i][j] != 0) {  
                result.values[i][j] = a.values[i][j] + b.values[i][j];  
            }  
        }  
    }  
    return result;  
}  
  
SparseMatrix multiply(SparseMatrix a, SparseMatrix b) {  
    SparseMatrix result;  
    result.row = a.row;  
    result.col = b.col;  
    result.values.resize(a.row * b.col);  
  
    for (int i = 0; i < a.row; i++) {  
        for (int j = 0; j < b.col; j++) {  
            int temp = 0;  
            for (int k = 0; k < a.col; k++) {  
                if (a.values[i][k] != 0 && b.values[k][j] != 0) {  
                    temp += a.values[i][k] * b.values[k][j];  
                }  
            }  
            result.values[i][j] = temp;  
        }  
    }  
    return result;  
}